package DataBase;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Vector;

import DataObjects.Supplier;

public class GetSupplierById 
{
	String suppId;
	
	public GetSupplierById(String id)
	{
		suppId=id;
	}
	
	
	public Vector<String> getSupplierById()
	{
		Vector<String> supplier=new Vector<String>();
		
		
		try {
			SQLConnection sc = new SQLConnection();		
			PreparedStatement ps = sc.getConnection().prepareStatement("SELECT suppID,suppName,suppPhoneNo,suppPhoneNo2,suppCellNo,suppMail,suppFax,suppContactMen,suppZipCode,suppCity,suppHouse,suppStreet,suppStatus  FROM Supplier WHERE suppID=?;");
			ps.setString(1,suppId);
			ResultSet rs=ps.executeQuery();
			ResultSetMetaData rsmd = rs.getMetaData();
						
			 while(rs.next())
		        {   

				 
		         for(int col = 1; col <= rsmd.getColumnCount(); col++) 
		         	{                      	                
		                int type = rsmd.getColumnType(col);
		                switch(type)
		                {
		                
		                    case Types.INTEGER :
		                    	supplier.add(new Integer(rs.getInt(col)).toString());
		                        break;
		                        
		                    case Types.VARCHAR :
		                    	supplier.add(rs.getString(col));
		                        break;
		                    case Types.DATE :
		                    	supplier.add(rs.getDate(col).toString());
		                        break;    
		                }//switch
		         	}//for
		         
		        }//while
			    ps.close();
				rs.close();
				sc.getConnection().close();
		}//try
	              catch (SQLException e) 
	              {
	                  e.printStackTrace();
	              }
		return supplier;
		
	}
}
